<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\loan\home;


use app\index\controller\Home;
use app\loan\model\Order;
use app\loan\model\Reference;
use think\Request;

/**
 * 前台首页控制器
 * @package app\index\controller
 */
class Index extends Home
{
    /**
     * @param Request $request
     * @return mixed|string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     *
     */
    public function index(Request $request){
        if(!$request->has('number') || $request->get('number') == ''){
            return '推荐人工号不能为空';
        }
        $number     = $request->only(['number'])['number'];
        $ref        = Reference::where('number',$number)->find();
        if(!$ref) return '工号不存在';
        session('ref_name',$ref['name']);
        session('ref_number',$number);
        return $this->fetch();
    }

    public function info(){
        return $this->fetch();
    }

    public function check(){
        $param = $this->request->only(['name','id_card','zhima','car','gongjijin','shebao','house']);
        $param['ref_number'] = session('ref_number');
        $param['ref_name']   = session('ref_name');
        $param['create_time'] = date('Y-m-d H:i:s');
        if(Order::isOrderExist($param['id_card'])) return json(['code'=>400,'msg'=>'您已提交过了.']);
        Order::create($param);
        session('name',$param['name']);
        session('id_card',$param['id_card']);
        return json(['code'=>200,'msg'=>'提交成功','url'=>url('score')]);
    }

    public function score(){
        return $this->fetch();
    }

    public function finish(){
        return $this->fetch();
    }

}
